using System.Collections;
using UnityEngine;

public class AimHUD : MonoBehaviour
{
	public AimPull pistolAim;

	public AimPull pistolHitAim;

	public AimPull pistolDeadAim;

	public AimPull avtoAim;

	public AimPull avtoHitAim;

	public AimPull avtoDeadAim;

	public AimPull rocketAim;

	public AimPull rocketHitAim;

	public AimPull rocketDeadAim;

	public AimPull grenadeAim;

	public AimPull grenadeHitAim;

	public AimPull grenadeDeadAim;

	public AimPull areaAim;

	public AimPull areaHitAim;

	public AimPull areaDeadAim;

	public AimPull meleAim;

	public AimPull meleHitAim;

	public AimPull meleDeadAim;

	public GameObject allAims;

	public float timeHit = 0.3f;

	public float timeDead = 0.3f;

	private AimPull normalAim;

	private AimPull hitAim;

	private AimPull deadAim;

	private Vector3 posStart;

	private AimTypes curAimType;

	public static AimHUD instance;

	private bool aimHidden;

	public void ToggleAimHUD(bool value)
	{
		allAims.SetActive(value);
		aimHidden = !value;
	}

	public void HideAimForTime(float time)
	{
		if (!aimHidden)
		{
			StartCoroutine(HideAimForTimeCoroutine(time));
		}
	}

	private IEnumerator HideAimForTimeCoroutine(float time)
	{
		ToggleAimHUD(false);
		yield return new WaitForSeconds(time);
		ToggleAimHUD(true);
	}

	private void Awake()
	{
		posStart = base.transform.localPosition;
		normalAim = pistolAim;
		hitAim = pistolHitAim;
		deadAim = pistolDeadAim;
		normalAim.gameObject.SetActive(true);
		instance = this;
	}

	public void SetActive(bool val)
	{
		allAims.SetActive(val);
	}

	public void SetPositionCenter(bool val)
	{
		if (settings.learningCompleted)
		{
			base.transform.localPosition = ((!val) ? posStart : Vector3.zero);
		}
	}

	public void SetAimType(AimTypes aimType)
	{
		if (curAimType != aimType)
		{
			if ((bool)normalAim)
			{
				normalAim.gameObject.SetActive(false);
			}
			if ((bool)hitAim)
			{
				hitAim.gameObject.SetActive(false);
			}
			if ((bool)deadAim)
			{
				deadAim.gameObject.SetActive(false);
			}
			switch (aimType)
			{
			case AimTypes.Pistol:
				normalAim = pistolAim;
				hitAim = pistolHitAim;
				deadAim = pistolDeadAim;
				break;
			case AimTypes.Avto:
				normalAim = avtoAim;
				hitAim = avtoHitAim;
				deadAim = avtoDeadAim;
				break;
			case AimTypes.Rocket:
				normalAim = rocketAim;
				hitAim = rocketHitAim;
				deadAim = rocketDeadAim;
				break;
			case AimTypes.Greande:
				normalAim = grenadeAim;
				hitAim = grenadeHitAim;
				deadAim = grenadeDeadAim;
				break;
			case AimTypes.Area:
				normalAim = areaAim;
				hitAim = areaHitAim;
				deadAim = areaDeadAim;
				break;
			case AimTypes.Mele:
				normalAim = meleAim;
				hitAim = meleHitAim;
				deadAim = meleDeadAim;
				break;
			}
			normalAim.gameObject.SetActive(true);
			curAimType = aimType;
		}
	}

	public void ShowAimHit(float damage, float DPS)
	{
		ShowAim(hitAim.gameObject, timeHit);
		AimHit component = hitAim.GetComponent<AimHit>();
		if (component != null)
		{
			component.SetDamage(damage, DPS);
		}
	}

	public void ShowAimDead()
	{
		ShowAim(deadAim.gameObject, timeDead);
	}

	public void hideNormalAim(bool val)
	{
		normalAim.gameObject.SetActive(!val);
	}

	private void ShowAim(GameObject obj, float time)
	{
		deadAim.gameObject.SetActive(false);
		CancelInvoke("ShowNormalAim");
		obj.SetActive(true);
		Invoke("ShowNormalAim", time);
	}

	private void ShowNormalAim()
	{
		deadAim.gameObject.SetActive(false);
	}

	public void Shot(float spread)
	{
		normalAim.Shot(spread);
		deadAim.Shot(spread);
		hitAim.Shot(spread);
	}
}
